package edu.umd.ion.wavemeter.client;

import name.maunz.client.timechart.TimechartInterface;
import name.maunz.client.timechart.TimechartWidget;

import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.xml.client.Element;

import edu.umd.ion.wavemeter.service.WavemeterChannelData;
import edu.umd.ion.wavemeter.service.WavemeterServiceAsync;

public class WavemeterTimechartWidget extends WavemeterChannelWidgetBase {
	private TimechartInterface Timechart;
	
	public WavemeterTimechartWidget(WavemeterServiceAsync service, int Number, boolean showunit, Panel errorPanel  )
	{
		super(service,Number,showunit,errorPanel);
	}	

	public void set(WavemeterChannelData data)
	{
		super.set(data);
		if (Active && Timechart.isEnabled() && data.Wavelength>0) {
			Timechart.addPoint(data.Timestamp/1000.0D,UnitBox.convertUnit(data.Wavelength));
		}
	}

	public void initialize(Element domelement) {
		if (domelement.hasAttribute("class")) {
			String backendclass = domelement.getAttribute("class");
			if (backendclass.equals("AdvancedTimechartWidget")) {
			} else {
				Timechart = new TimechartWidget();
			}
		} else {
			Timechart = new TimechartWidget();
		}
		Timechart.initialize(domelement);
		this.initWidget(Timechart.getWidget());
	}

}
